home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagn_r.zip / OOP.SWG / 0002_COUNTDLG.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  92 lines

  1. {
  2. > Some trouble-shooting With Turbo Vision, AGAIN!
  3. > If i want to impelement this source code to
  4. > show x in a Window, how do i do that!!
  5.  
  6. > For x:=1 to 100 do
  7. >    WriteLn (x);
  8.  
  9. > That means that i want show x counting in the
  10. > Window..........
  11.  
  12. Here a simple method you can use to get started. It has been tested, and it
  13. does not do much, except show a counting dialog box.
  14. }
  15.  
  16. Unit CountDlg;
  17.  
  18. Interface
  19. Uses
  20.   Objects, dialogs, views, drivers;
  21. Type
  22.   KDialog = Object(TDialog)
  23.               Count : Word;
  24.               ps    : PStaticText;
  25.               Constructor Init(Var bounds:Trect;ATitle:TTitleStr);
  26.               Procedure HandleEvent(Var Event:TEvent); virtual;
  27.              end;
  28.   PKDialog = ^KDialog;
  29.  
  30. Implementation
  31.  
  32. Function NumStr(n:Word):String;
  33. Var
  34.   S : String;
  35. begin
  36.   Str(n,s);
  37.   NumStr := s;
  38. end;
  39.  
  40. Constructor KDialog.Init(Var Bounds:TRect;ATitle:TTitleStr);
  41. Var
  42.   r : TRect;
  43. begin
  44.   inherited init(Bounds,ATitle);
  45.   Count := 0;
  46.   GetExtent(r);
  47.   r.grow(-1,-2); r.b.y := r.a.y + 1;
  48.   new(ps,init(r,'  Cyclycal counter := '+NumStr(Count)));
  49.   insert(ps);
  50. end;
  51.  
  52. Procedure KDialog.HandleEvent(Var Event:TEvent);
  53. begin
  54.   inc(Count);
  55.   if count > 10000 then count := 0;
  56.   DisposeStr(ps^.Text);
  57.   ps^.Text := NewStr('  Cyclycal count := '+NumStr(Count));
  58.   ps^.Draw;
  59.   Inherited HandleEvent(Event);
  60. end;
  61.  
  62. end.
  63.  
  64. {
  65. And... the associated application to try it With ...
  66. }
  67.  
  68. Program GenApp;
  69. Uses
  70.   Objects, App, Views, Dialogs, CountDlg;
  71. Type
  72.   GenericApp = Object(TApplication)
  73.                  Procedure Run; Virtual;
  74.                end;
  75.  
  76. Procedure GenericApp.Run;
  77. Var
  78.   r  : TRect;
  79. begin
  80.   GetExtent(R);
  81.   R.Grow(-26,-10);
  82.   ExecuteDialog(new(PKDialog,init(r,'Test Counter')),nil);
  83. end;
  84.  
  85. Var MyApp : GenericApp;
  86.  
  87. begin
  88.   MyApp.Init;
  89.   MyApp.Run;
  90.   MyApp.Done;
  91. end.
  92.